# coding:utf-8
# orangleliu
# title: handler.py

import subprocess as sb
import tempfile

from os import kill
import signal
import time

out_temp = tempfile.SpooledTemporaryFile()

talkpipe = sb.Popen(['python', 'echo.py'], shell=True, stdout=out_temp.fileno())
talkpipe.wait()
out_temp.seek(0)
try:
    while True:
        line = out_temp.readline()
        if line:
            print("SERVER HEARD", line.strip())
        else:
            print("no data")
        time.sleep(2)

except KeyboardInterrupt:
    print("Killing child...")
    kill(talkpipe.pid, signal.SIGTERM)
